package com.resys.server.controller.staff;

import com.resys.entity.dto.LogDto;
import com.resys.entity.dto.MtroomDto;
import com.resys.entity.dto.TokenUserInfoDto;
import com.resys.entity.po.Meetingroom;
import com.resys.entity.query.MeetingroomQuery;
import com.resys.entity.vo.ResponseVO;
import com.resys.server.controller.ABaseController;
import com.resys.service.MeetingroomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController("StaffMeetingRoomController")
@Api(tags = "员工接口-会议室管理")
@RequestMapping("/staff/meetingRoom")
public class MeetingRoomController extends ABaseController {
    @Resource
    private MeetingroomService meetingroomService;
    @GetMapping
    @ApiOperation("查询会议室")
    public ResponseVO list(){
        MeetingroomQuery query = new MeetingroomQuery();
        return getSuccessResponseVO(meetingroomService.findListByParam(query));
    }
    @ApiOperation("模糊搜索会议室")
    @GetMapping("/search")
    public ResponseVO search(String FuzzyName){
        MeetingroomQuery query = new MeetingroomQuery();
        query.setNameFuzzy(FuzzyName);
        List<Meetingroom> list = meetingroomService.findListByParam(query);
        return getSuccessResponseVO(list);

    }
    @ApiOperation("修改会议室状态")
    @PostMapping("/update")
    public ResponseVO update(@RequestBody MtroomDto mtroomDto){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfo("staff");

        Meetingroom room = meetingroomService.getMeetingroomByRoomId(mtroomDto.getRoomId());
        LogDto logDto= new LogDto();
        logDto.setRoomId(mtroomDto.getRoomId());
        logDto.setUserId(tokenUserInfoDto.getUserId());
        logDto.setNewStatus(mtroomDto.getStatus());
        logDto.setOldStatus(room.getStatus());
        meetingroomService.updateStatus(mtroomDto);
        writelog(logDto);

        return getSuccessResponseVO("修改成功");
    }
}
